#ifndef POINTCLOUD_PROCESSOR_HPP
#define POINTCLOUD_PROCESSOR_HPP

#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <Eigen/Geometry>
#include <memory>
#include "voxel_voting_filter.hpp"


namespace mult_lidar{

    struct ProcessingParams
    {
        //坐标变换参数
        float radar_height = 1.10f;
        float rotation_angle = 3.8f;


        //坐标轴滤波参数
        float x_min = 0.0f;
        float x_max = 1.9f;
        float y_min = -2.5f;
        float y_max = 2.5f;
        float z_min = 0.0f;
        float z_max = 1.3f;

        //激光点云强度滤波参数
        float intensity_threshold = 38.0f;

        //体素方格大小
        float voxel_leaf_size = 0.02f;

        //最大累积帧数
        int max_frames = 6;

        //离群点移除参数
        int sor_mean_k = 500;
        float sor_std_mul = 1.2f;
    };


    class PointCloudProcessor{

        public:

        PointCloudProcessor();

        void setParameters(const ProcessingParams& params);
        //坐标系变换
        void transformToBaseFrame(pcl::PointCloud<pcl::PointXYZI>::Ptr cloud);
        //坐标系过滤
        void filterPointCloud(pcl::PointCloud<pcl::PointXYZI>::Ptr cloud);
        //点云强度过滤
        void intensityBasedFilter(pcl::PointCloud<pcl::PointXYZI>::Ptr cloud);
        //降采样过滤
        void downsampleCloud(pcl::PointCloud<pcl::PointXYZI>::Ptr cloud);
        //离群点过滤
        void removeOutliers(pcl::PointCloud<pcl::PointXYZI>::Ptr cloud);
        //点云积累
        void accumulateCloud(pcl::PointCloud<pcl::PointXYZI>::Ptr input_cloud,
                            pcl::PointCloud<pcl::PointXYZI>::Ptr output_cloud);

        bool isAccumulationComplete() const;

        void resetAccumulation();

        int getFrameCounter() const {return frame_counter_;}
        int getMaxFrames() const { return params_.max_frames; }


        private:

        ProcessingParams params_;
        int frame_counter_;
        Eigen::Affine3f transform_matrix_;

        std::unique_ptr<VoxelVotingFilter> voxel_filter_;

    };
    
}

#endif